namespace Nice157Advices.Advices
{
    /// <summary>
    /// 44.理解委托中的协变
    /// </summary>
    public static class _44
    {
        private delegate T GetEmployeeHandler<out T> (string name);

        public static void Go ()
        {
            GetEmployeeHandler<Manager> getAManager = GetAManager;
            // 协变
            GetEmployeeHandler<Employee> getAEmployee = getAManager;
            Employee e = getAEmployee("Mike");
        }

        private static Manager GetAManager (string name)
        {
            System.Console.WriteLine ("我是经理: " + name);
            return new Manager () { Name = name };
        }
        private static Employee GetAEmployee (string name)
        {
            System.Console.WriteLine ("我是雇员: " + name);
            return new Employee () { Name = name };
        }

        private class Employee
        {
            public string Name { get; set; }
        }

        private class Programmer : Employee { }
        private class Manager : Employee { }
    }
}